<!DOCTYPE html>
<!-- Created by 白墨 on 2021/4/17 22:35:28-->
<html lang="zh-cmn-Hans-CN" xmlns:th="http://www.thymeleaf.org">

<head th:replace="_fragments ::head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../static/css/typo.css" th:href="@{/css/typo.css}">
    <link rel="stylesheet" href="../static/css/animate.css" th:href="@{/css/animate.css}">
    <link rel="stylesheet" href="../static/lib/prism/prism.css" th:href="@{/lib/prism/prism.css}">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css" th:href="@{/lib/tocbot/tocbot.css}">
    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="stylesheet" href="../static/lib/editormd/css/editormd.min.css"
          th:href="@{/lib/editormd/css/editormd.min.css}">
</head>

<body>

<!-- 导航 -->
<nav th:replace="_fragments::menu(1)" class="ui inverted attached segment "></nav>


<!-- 中间部分 -->
<div id="waypoint" class="m-container m-padded-tb-big">
    <div class="ui container animated fadeInUp">
        <div class="ui attached segment tm">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="../static/image/me.jpg" th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image">
                    <div class="content"><a href="#" class="header" th:text="${blog.user.nickname}">白墨</a></div>
                </div>
                <div class="item">
                    <i class=" calendar icon"></i> <span class="m-text-small"
                                                         th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">
                                                        时间</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i> <span class="m-text-small" th:text="${blog.views}">浏览数</span>
                </div>
            </div>
        </div>
        <!-- 图片区域 -->
        <div class="ui attached segment tm">
            <img src="../static/image/bg.png" th:src="@{${blog.firstPicture}}" alt="" class="ui fluid rounded image">
        </div>
        <!-- 内容 -->
        <div class="ui attached segment tm">
            <div class="ui right aligned basic segment">
                <div class="ui basic label" th:classappend="${blog.flag == '原创'?'orange':(blog.flag == '转载'?'green':'red') }" th:text="${blog.flag}">原创</div>
            </div>
            <h2 class="ui center aligned header" th:text="${blog.title}">标题</h2>
            <br>
            <!--                博客内容-->
            <div id="content" class="typo typo-selection js-toc-content  m-padding-lr-responsive m-padded-tb-large">
                <textarea style="display:none;" th:text="${blog.content}"></textarea>
            </div>
            <!--转载-->
            <div class="m-padding-lr-responsive" th:if="${blog.sourceUrl!=null&&blog.sourceUrl!=''}">
                原文地址：<a th:text="${blog.sourceUrl}" th:href="${blog.sourceUrl}"></a>
            </div>
            <br/>
            <!-- 标签 -->
            <div class="m-padding-lr-responsive">
                <div class="ui basic blue left pointing label " th:each="tag:${blog.tags}" th:text="${tag.name}">标签
                </div>
            </div>
            <!-- 赞赏功能 -->
            <div th:if="${blog.appreciation}">
                <div class="ui center aligned basic segment">
                    <button id="payButton" class="ui orange basic circular button">赞赏</button>
                </div>
                <div class="ui payQR flowing popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <div class="image">
                                <img src="../static/image/wxzf.png" th:src="@{/image/wxzf.png}" alt=""
                                     class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>微信</div>
                            </div>
                            <div class="image">
                                <img src="../static/image/zfb.png" th:src="@{/image/zfb.png}" alt=""
                                     class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>支付宝</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 博客信息 -->
        <div class="ui attached positive message tm" th:if="${blog.shareStatement}">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span th:text="${blog.user.nickname}">作者</span><a href="" th:href="@{/about}"
                                                                                 target="_blank">(联系作者)</a></li>
                        <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}"></span></li>
                        <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                        <li>公众号转载：请在文末添加作者公众号二维码</li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img src="../static/image/mine.png" th:src="@{/image/mine.png}" alt=""
                         class="ui right floated rounded bordered image"
                         style="width: 110px">
                </div>
            </div>
        </div>
        <!-- 留言区域 -->
        <div class="ui attached bottom segment tm" th:if="${blog.commentEnabled}">
            <div id="comment-container" class="ui blue segment tm-qt">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${blog.comments}">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}"/>
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">昵称</span>
                                    <div class="ui mini basic orange left pointing label m-padded-mini"
                                         th:if="${comment.adminComment}">博主
                                    </div>
                                </a>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">时间</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    评论内容
                                </div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname},data-targetname=''"
                                       onclick="reply(this)">回复</a>
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:if="${session.user!=null}"
                                       th:attr="data-commentid=${comment.id},data-email=${comment.email},data-adnim=${comment.adminComment}"
                                       onclick="del(this)">删除</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)>0}">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">昵称</span>
                                            <div class="ui mini basic orange left pointing label m-padded-mini"
                                                 th:if="${reply.adminComment}">博主
                                            </div>
                                            &nbsp;<span
                                                th:text='${(reply.targetName!=null and reply.targetName.length()>0)?"回复：@ "+reply.targetName:""}'
                                                class="m-blue">回复的人</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date"
                                                  th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">时间</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">
                                            评论内容
                                        </div>
                                        <div class="actions">
                                            <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                               th:attr="data-commentid=${comment.id},data-commentnickname=${reply.nickname},data-targetname=${reply.nickname}"
                                               onclick="reply(this)">回复</a>
                                            <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                               th:if="${session.user!=null}"
                                               th:attr="data-commentid=${reply.id},data-email=${reply.email},data-adnim=${comment.adminComment}"
                                               onclick="del(this)">删除</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--                评论功能-->
            <div id="comment-form" class="ui form tm-qt">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <input type="hidden" name="targetName" value="">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input tm-qt">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" class="tm-qt" placeholder="你的昵称"
                                   th:value="${session.user}!=null ? ${session.user.nickname}"/>
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input tm-qt">
                            <i class="mail icon"></i>
                            <input type="text" name="email" class="tm-qt" placeholder="邮箱（不会被公开）"
                                   th:value="${session.user}!=null ? ${session.user.email}"/>
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui toggle checkbox ">
                            <input type="checkbox" name="inform"/>
                            <label>回复通知</label>
                        </div>
                    </div>
                    <div class="field  m-margin-bottom-small m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui green button m-mobile-wide"><i
                                class="edit icon"></i>发布
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--        右下角功能-->
    <div id="toolbar" class="m-padded-tb animated fadeIn m-fixed" style="display: none; bottom: 200px;right: 0px">
        <div class="ui vertical icon buttons ">
            <button type="button" class="ui toc blue button">目录</button>
            <a href="#comment-container" class="ui blue button">留言</a>
            <button class="ui wechat icon button"><i class="weixin icon"></i></button>
            <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>
            <a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=zLukpbippLuMqqO0oa2loOKvo6E" style="text-decoration:none;"><img src="http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_01.png"/></a>
        </div>
    </div>

    <div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
        <ol class="js-toc">

        </ol>
    </div>

    <div id="qrcode" class="ui wechat-qr flowing popup transition hidden" style="width: 130px !important;">
                <img th:src="@{/image/mine.png}" alt="" class="ui rounded image" style="width: 120px !important;">
    </div>
    <br>
    <br>
</div>


<!-- 底部 -->
<footer th:replace="_fragments::footer" class="ui inverted vertical segment m-padded-tb-massive"></footer>


<script src="https://lib.baomitu.com/jquery/3.5.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>

<script src="../static/lib/prism/prism.js" th:src="@{/lib/prism/prism.js}"></script>
<script src="/lib/tocbot/tocbot.js" th:src="@{/lib/tocbot/tocbot.js}"></script>
<script src="/lib/qrcode/qrcode.min.js" th:src="@{/lib/qrcode/qrcode.min.js}"></script>
<script src="/lib/waypoints/jquery.waypoints.min.js" th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>
<script src="../static/js/APlayer.min.js" th:src="@{/js/APlayer.min.js}"></script>
<script src="../static/js/music.js" th:src="@{/js/music.js}"></script>
<!--    雪花特效-->
<script src="../static/js/snow.js" th:src="@{/js/snow.js}"></script>
<!--板娘 -->
<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>

<script src="../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script>
<script src="../static/lib/editormd/lib/marked.min.js" th:src="@{/lib/editormd/lib/marked.min.js}"></script>
<script src="../static/lib/editormd/lib/prettify.min.js" th:src="@{/lib/editormd/lib/prettify.min.js}"></script>
<script type="text/javascript">
    var testEditor;
    $(function () {
        testEditor = editormd.markdownToHTML("content", {//注意：这里是上面DIV的id
            htmlDecode: "style,script,iframe",
            emoji: true,
            taskList: true,
            tex: true, // 默认不解析
            sequenceDiagram: true, // 默认不解析
            codeFold: true,
        });
    });
</script>
<script>
    L2Dwidget.init({
        "model": {
            jsonPath: "https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json",
            "scale": 1
        },
        "display": {
            "position": "right",
            "width": 100,
            "height": 200,
            "hOffset": 0,
            "vOffset": -20
        },
        "mobile": {
            "show": true,
            "scale": 0.5
        },
        "react": {
            "opacityDefault": 1,
            "opacityOnHover": 0.2
        }
    });
</script>

<script type="text/javascript">
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
        popup: $('.payQR.popup'),
        on: 'click',
        position: 'bottom center'
    });

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
    });

    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });

    $('.wechat').popup({
        popup: $('.wechat-qr'),
        position: 'left center'
    });

    var serurl = "[[#{blog.serurl}]]";
    var url = "[[@{/blog/{id}(id=${blog.id})}]]";
    var qrcode = new QRCode("qrcode", {
        text: serurl + url,
        width: 110,
        height: 110,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });

    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500);
    });


    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })


    //评论表单验证
    $('.ui.form').form({
        on: 'blur',
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的昵称'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });

    $(function () {
        $("#comment-container").load("[[@{/comments/{id}(id=${blog.id})}]]");
    });


    $('#commentpost-btn').click(function () {
        let boo = $('.ui.form').form('validate form');
        if (boo) {
            postData();
        } else {
        }
    });

    function postData() {
        $("#comment-container").load("[[@{/comments}]]",{
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val(),
            "inform": $("[name='inform']").val(),
            "targetName": $("[name='targetName']").val()
        }, function (responseTxt, statusTxt, xhr) {
            $(window).scrollTo($('#comment-container'), 500);
            clearContent();
        });
    }

    function clearContent() {
        let content = $("[name='content']");
        content.val('');
        content.attr("placeholder", "请输入评论信息...");
        $("[name='parentComment.id']").val(-1);
        $("[name='targetName']").val('');
    }

    function reply(obj) {
        let commentId = $(obj).data('commentid');
        let commentNickname = $(obj).data('commentnickname');
        let targetName = $(obj).data('targetname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $("[name='targetName']").val(targetName);
        $(window).scrollTo($('#comment-form'), 500);
    }

    function del(obj) {
        if (confirm("你确定要删除吗？")){
            let id = $(obj).data('commentid');
            let email = $(obj).data('email');
            let adminComment = $(obj).data('adnim');
            $("#comment-container").load("[[@{/admin/comment/delete}]]",{
                "blog.id": $("[name='blog.id']").val(),
                "id": id,
                "email": email,
                "adminComment":adminComment
            });
        }

    }

    $('#newblog-container').load("[[@{/footer/newblog}]]");
</script>
</body>

</html>